{include file="common/mobile/header" title="登录" /}

<link rel="stylesheet" href="__CSS__/mobile-login.css"/>

<div class="login-container" id="login">
    <div class="login-main">
        <div class="login-header layui-clear">
            <table>
                <tr>
                    <td align="right">
                        <div class="logo">
                            <img src="{$siteConfig.slogo}"/>
                        </div>
                    </td>
                    <td align="left">
                        <div class="title">
                            <h2>{$enterprise.title}</h2>
                            <p>{$siteConfig.siteSlogan}</p>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="login-body">
            <div class="login-types">
                {if condition="$loginType['mobile']"}
                <!-- 手机号登录 -->
                <div class="login-type" data-type="mobile" style="display: none;">
                    <div class="login-item">
                        <i class="layui-icon layui-icon-cellphone"></i>
                        <input class="layui-input" type="text" name="mobile" placeholder="手机号"/>
                    </div>
                    <div class="login-item">
                        <i class="layui-icon layui-icon-password"></i>
                        <input class="layui-input" type="password" name="password" placeholder="密码"/>
                    </div>
                </div>
                {/if}
                {if condition="$loginType['username']"}
                <!-- 账号密码登录 TODO -->
                <div class="login-type" data-type="username" style="display: none;">

                </div>
                {/if}
            </div>
            <div class="login-tools layui-clear">
                {if condition="$loginType['mobile']"}
                <div class="login-tool">
                    <a href="/core/enterprise.user/resetPassword?eid={$eid}">忘记密码？</a>
                </div>
                {/if}
            </div>
            <div class="login-btns">
                <div class="login-btn">
                    <button class="layui-btn layui-btn-fluid login-submit">登&nbsp;&nbsp;&nbsp;录</button>
                </div>
            </div>
        </div>
        <div class="login-footer">
            {$siteConfig.copyright}
        </div>
    </div>
</div>

<script>
    //显示第一个登录内容
    var type = $("#login .login-types .login-type").first().show().attr("data-type");
    $("#login .login-types").attr("data-type", type);

    $("#login .login-submit").click(function () {
        var type = $("#login .login-types").attr("data-type");
        if (type == 'mobile') {
            doMobileLogin();
        }
    });

    /**
     * 手机号登录
     */
    function doMobileLogin() {
        var mobile = $("#login .login-type[data-type='mobile'] input[name='mobile']").val();
        var password = $("#login .login-type[data-type='mobile'] input[name='password']").val();

        if (!checkMobile(mobile)) {
            layer.alert("请输入正确的手机号");
            return;
        }
        if (!password) {
            layer.alert("请输入密码");
            return;
        }

        g.loading();
        $.post("/core/enterprise.user/mobileLogin?eid={$eid}", {mobile: mobile, password: password}, function (ret) {
            g.loading(false);
            if (ret.code == 1) {
                layer.msg(ret.msg);
                document.location.href = ret.url;
            } else {
                layer.alert(ret.msg);
            }
        }, "json");
    }

    /**
     * 检查手机号
     *
     * @param mobile
     * @returns {boolean}
     */
    function checkMobile(mobile) {
        if (!mobile) {
            return false;
        }
        var mobileReg = /^[1][3,4,5,7,8][0-9]{9}$/;
        if (!mobileReg.test(mobile)) {
            return false;
        } else {
            return true;
        }
    }

    $(document).ready(function () {
        g.setElementVerticalMiddle("#login", 10);
    });
</script>

{include file="common/mobile/footer"/}
